// https://www.bilibili.com/video/BV11E411o7Fb?p=3
#include <bits/stdc++.h>
using namespace std;

int n;
vector<vector<int>> edges;
vector<bool> visited;

void dataInput(int& n,vector<vector<int>>& edges,vector<bool>& visited);

void dfs(int node){
    if(visited[node]){
        return;
    }
    cout<<node<<endl;
    visited[node] = true;
    vector<int> neighbours = edges[node];
    for(auto neighbour : neighbours){
        dfs(neighbour);
    }
}
int main(){
    //initial the grap;
    dataInput(n,edges,visited);
    for(int i = 0 ; i< edges.size(); i++){
        dfs(i);
    }

}

void dataInput(int& n,vector<vector<int>>& edges,vector<bool>& visited){
    cin >> n ;
    edges.resize(n);
    visited.resize(n);
    for(int i = 0; i< n; i++){
        int len;
        cin >>len;
        for(int j =0; j < len;j ++)
        {
            int value;
            cin >> value;
            edges[i].push_back(value);
        }
    }
}